package com.yygo.webapp.controller.loanrequest;

import com.yygo.model.LoanRequest;
import com.yygo.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.security.Principal;

/**
 * Created by tiansha on 2015/7/29.
 */
@Controller
@RequestMapping("/transferCA")
public class TransferCAController extends BaseLoanRequestFormController {

    @RequestMapping(method = RequestMethod.POST)
    public String transferCA(@RequestParam(required = true, value = "reqId") Long reqId, @RequestParam(required = true, value = "pbocComment") String pbocComment, Principal principal) throws IllegalAccessException {
        LoanRequest loanRequest = loanRequestManager.loadWholeLoanRequest(reqId);
        loanRequest.setPbocComment(pbocComment);
        User loginUser = userManager.getUserByUsername(principal.getName());
        handleAction(ACTION_ccApprove, loanRequest, null, loginUser);
        loanRequestManager.saveLoanRequest(loanRequest);
        return "redirect:/myloanrequests?status=request_audit";
    }
}
